<template>
  <div>
    <el-table :data="localTasks" size="mini" border :style="{ width: '100%', marginTop: '15px' }" row-key="id">
      <el-table-column prop="userName" label="执行人" width="100">
        <template slot-scope="scope">
          <div>
            {{ scope.row.receiveUserName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="taskDeptName" label="所属部门" width="120"> </el-table-column>
      <el-table-column prop="taskContent" label="任务内容"> </el-table-column>
      <el-table-column prop="helpContent" label="辅助信息"> </el-table-column>
      <!-- <el-table-column label="详情" type="expand">
        <template slot-scope="scope">
          <task-submit-view :taskData="scope.row" />
        </template>
      </el-table-column> -->
    </el-table>
  </div>
</template>

<script>
import * as HandleApi from "@/api/response/handle.js";
import * as DrillApi from "@/api/drill/drill.js";
import TaskSubmitView from "@/views/components/taskSubmitView/index.vue";
export default {
  name: "HandleTaskTableView",
  components: { TaskSubmitView },
  props: {
    tasks: {
      type: Array,
      default: [],
    },
    type: {
      type: Number,
      default: 2,
    },
    handleId: {
      type: Number,
      default: 0,
    },
    levelId: {
      type: Number,
      default: 0,
    },
    time: { type: Number, default: 1000 * 60 * 0.1 },
  },
  data() {
    return {
      timer: null,
      localTasks: [],
      taskId: 0,
    };
  },
  mounted() {
    if (this.tasks.length > 0) {
      this.localTasks = this.tasks;
    }
  },
  methods: {
    getTasks() {
      if (this.type == 1) {
        if (this.handleId != 0) {
          DrillApi.getDrillTasks(this.handleId).then(res => {
            this.localTasks = res.data;
            this.$emit("refreshCurrentTasks");
          });
        }
      } else {
        if (this.handleId != 0 && this.levelId != 0) {
          HandleApi.getHandleLevelTasks({
            handleId: this.handleId,
            levelId: this.levelId,
          }).then(res => {
            this.localTasks = res.data;
            this.$emit("refreshCurrentTasks");
          });
        }
      }
    },
    handleStopTask(data) {
      // 删除或者取消任务
      this.$modal.loading(data.status == 1 ? "正在取消任务，请稍后..." : "正在删除任务，请稍后...");
      HandleApi.stopTask(data.id).then(res => {
        this.$modal.closeLoading();
        if (res.code == 200) {
          this.$modal.msgSuccess(res.msg);
        } else {
          this.$modal.msgError(res.msg);
        }
        this.$emit("refreshCurrentTasks");
      });
    },
  },
  watch: {
    tasks(n, o) {
      this.localTasks = n;
    },
  },
};
</script>

<style lang="scss" scoped></style>
